package com.tencreat.mall.controller.admin.im;

import java.util.List;

import com.tencreat.common.core.HttpResult;
import com.tencreat.domain.im.ImPhrasesType;
import com.tencreat.service.IImPhrasesTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.tencreat.common.annotation.Log;
import com.tencreat.common.core.controller.BaseController;
import com.tencreat.common.core.domain.AjaxResult;
import com.tencreat.common.enums.BusinessType;
import com.tencreat.common.utils.poi.ExcelUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;

/**
 * 常用语分类Controller
 *
 * @author tencreat
 * @company 深圳腾创互联科技有限公司
 * @link https://tencreat.com
 * @since 2023-11-22
 */
@Api(tags = "IM  常用语分类api")
@RestController
@RequestMapping("/mall/im/type")
@RequiredArgsConstructor
public class ImPhrasesTypeController extends BaseController {

    private final IImPhrasesTypeService imPhrasesTypeService;

    @ApiOperation(value = "查询常用语分类列表")
    @PostMapping("/list")
    HttpResult<IPage<ImPhrasesType>> list(@RequestBody ImPhrasesType imPhrasesType) {
        IPage<ImPhrasesType> iPage = generatePage(imPhrasesType);
        return HttpResult.ok(imPhrasesTypeService.page(iPage, imPhrasesType));
    }

    @ApiOperation(value = "导出常用语分类列表")
    @Log(title = "常用语分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    AjaxResult export(@RequestBody ImPhrasesType imPhrasesType) {
        List<ImPhrasesType> list = imPhrasesTypeService.page(getMaxPage(), imPhrasesType).getRecords();
        ExcelUtil<ImPhrasesType> util = new ExcelUtil<>(ImPhrasesType.class);
        return util.exportExcel(list, "常用语分类");
    }

    @ApiOperation(value = "获取常用语分类详细信息")
    @GetMapping(value = "/getInfo/{id}")
    HttpResult<ImPhrasesType> getInfo(@PathVariable("id") Long id) {
        return HttpResult.ok(imPhrasesTypeService.getById(id));
    }

    @ApiOperation(value = "新增常用语分类")
    @Log(title = "常用语分类", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    HttpResult<Boolean> add(@RequestBody @Validated ImPhrasesType imPhrasesType) {
        return to(imPhrasesTypeService.save(imPhrasesType));
    }

    @ApiOperation(value = "修改常用语分类")
    @Log(title = "常用语分类", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    HttpResult<Boolean> edit(@RequestBody @Validated ImPhrasesType imPhrasesType) {
        return to(imPhrasesTypeService.updateById(imPhrasesType));
    }

    @ApiOperation(value = "删除常用语分类")
    @Log(title = "常用语分类", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    HttpResult<Boolean> remove(@RequestBody List<Long> ids) {
        return to(imPhrasesTypeService.removeByIds(ids));
    }
}